﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Emergency4.Dal;
using Emergency4.From;
using Emergency4.Session;


namespace Emergency4
{
    /// <summary>
    /// 登录窗口
    /// </summary>
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 登录按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {//当前窗口的用户名、密码
            string usename = this.username.Text;
            string password = this.password.Text;
            if(usename==null || usename== "")
            {
                MessageBox.Show("用户名不能为空！");
                return;
            }
            if (password == null || password == "")
            {
                MessageBox.Show("密码不能为空！");
                return;
            }
            Employee ep = EmployeeDal.findByEmployeeUsername(usename);
            if(ep!= null)
            {
                if (ep.Password.Equals(password))//登录成功
                {
                    if(ep.isAdmin.Equals(true))//跳转维修经理窗口
                    { 
                        Admin admin  = new Admin();
                        admin.Show();//弹出该页面
                    }
                    else//员工
                    {
                        EmergencyMaintenanceManagement em = new EmergencyMaintenanceManagement();
                        em.Show();
                    }
                    //当前窗口隐藏
                    this.Hide();
                }
                else
                {
                    MessageBox.Show("密码错误！");
                    return;
                }
            }
            else
            {
                MessageBox.Show("用户名不存在！");
                return;
            }

        }
        /// <summary>
        /// 登录窗口的取消 按钮 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            //关闭该窗口
            this.Close();
        }
    }
}
